<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/3/11
 * Time: 22:05
 */

namespace Home\Controller;

use Think\Controller;

class StuformController extends Controller
{

    public function _initialize(){
        header("content-type:text/html; charset=utf-8");
        $flag = session("?username");
        if(!$flag){
            $this->error("未登录",U('Login/index'));
        }
    }

    public function index()
    {
        $title = I("get.title");
        if (!empty($title)) {
            $depinfo=M("depinfo");
            $depData=$depinfo->select();

            $classinfo=M("classinfo");
            $classData=$classinfo->select();

            $this->assign("title", $title)->assign("depData",$depData)->assign("classData",$classData);;
            $this->display();
        } else {
            $this->error("非法操作！");
        }
    }

    public function add(){
        $post["enroll"]=htmlspecialchars(trim(I("enroll")));
        $post["stuid"]=htmlspecialchars(trim(I("stuid")));
        $post["name"]=htmlspecialchars(trim(I("name")));
        $post["dept"]=htmlspecialchars(trim(I("dept")));
        $post["class"]=htmlspecialchars(trim(I("class")));
        $post["addtime"]=date("Y-m-d h:i:s", time());

        $stuenroll=M("stuenroll");
        if($stuenroll->add($post)){
            $this->success("报名成功",U("Index/index"));
//            dump($post);
        }else{
            $this->error("报名失败");
        }


    }

}